<?php
if ($_GET['ident0'] <> NULL)  {  //only if GET request from pop7.js
$n=0;
//$project_id = $_GET['project_id'];
//echo 'Project_id is: '.$project_id.'<br />';

foreach($_GET as $name => $value) {
	//echo "$name : $value<br>";
	$getArray[$n][0] = $name;
	$getArray[$n][1] = $value;
	$n++;

}
$n=($n-1)/3;
//echo 'num markers is: '.$n;
//NEED TO CREATE AN ARRAY iden,x,y from the GET data
for ($i=0;$i<$n;$i++) {
	$a = $i*3 +1;
	$b = $i*3 +2;
	$c = $i*3 +3;
$ident=$getArray[$a][1];
$posx=$getArray[$b][1];
$posy=$getArray[$c][1];
//echo $ident;
//if the markers ident start "mark" they are new so INSERT
	if (strpos($ident,"ark") && $posx > 0 && $posy > 0) {
		//INSERT new makers if in range and no existing id; 
		$query = "INSERT into markers (project,posx,posy) VALUES ('$project_id','$posx','$posy')";
		$result = mysql_query($query);
		if ( !$result )
		{
			echo ( "<P>Error inserting markers update_markers.php: " . mysql_error() . "</P>" );
		}
		else
		{
			//echo '<p>markers successfully inserted</p>';
		}
	}
	elseif ($posx < 0 || $posy < 0) {
			//echo 'delete '.$ident.'<br/>';
			$query = "DELETE FROM markers WHERE ident = '$ident' AND project = '$project_id'";
		$result = mysql_query($query);
		if ( !$result )
		{
			echo ( "<P>Error deleting existing markers update_markers.php: " . mysql_error() . "</P>" );
		}
		else
		{
			//echo '<p>markers successfully deleted</p>';
		}
		}
	else {
		//echo 'locate existing markers ident '.$ident.' and project '.$project_id.'<br />';
		$query = "UPDATE markers SET posx = '$posx', posy = '$posy' WHERE ident = '$ident' AND project = '$project_id'";
		$result = mysql_query($query);
		if ( !$result )
		{
			echo ( "<P>Error updating existing markers update_markers.php: " . mysql_error() . "</P>" );
		}
		else
		{
			//echo '<p>markers successfully updated</p>';
		}
	}
	


}//for

}//top if


//echo '<p><a href="../ed05.php?project_id='.$project_id.'">Click to edit pop-ups</a></p>';
?>
